<template>
  <div class="contranier">
    <div class="contranier-title">
      <img
        class="mmg"
        src="../../assets/images/icon_h1h6rlt6v8d/zuojiantou7.png"
        mode=""
        @click="imaged"
      />
    </div>
    <div class="contranier-content">
      <div>
        <span>体质类型</span>
        <van-radio-group
          v-model="selectedValues"
          @change="handleCheckboxChange"
        >
          <van-radio v-for="(item) in sct" :key="item" :name="item">{{
            item.Tz_Name
          }}<span class="tz" v-show="item.Tz_Id==item1.Tz_Id" v-for="item1 in options" :key="item1">(推荐 {{item1.Tz_Name}})</span></van-radio>
        </van-radio-group>
      </div>
      <div>
        <span>偏颇程度</span>
         <van-radio-group
          v-model="selectedValues1"
          @change="handleCheckboxChange1"
        >
          <van-radio v-for="item in sct1" :key="item" :name="item">{{
            item.ppname
          }}<span></span></van-radio>
        </van-radio-group>
      </div>
    </div>
    <div class="contranier-footer">
      <div class="dialog-footer">
        <el-button class="t1" type="primary" @click="submitForm" :disabled="isButtonDisabled"
          >确 定</el-button
        >
        <el-button class="t2" @click="dialogVisible = false">取 消</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import { showDialog } from "vant";
import { userStore } from "../../stores/user.ts";
export default {
  data() {
    return {
      options:[],
      User_Code: "",
      RltTzID: "",
      Interface_Code: "",
      selectedValues: "",
      selectedValues1:"",
      RltTzStr:"",
      RltTzStr1:"",
      RltTzStr2:"",
      ZytzQuestions:[],
      sct: [],
      isButtonDisabled:false,
      sct1:[
        {ppid:"0",ppname:"是"},
         {ppid:"1",ppname:"倾向是"}
      ]
    };
  },
  
  created() {
    this.Interface_Code = sessionStorage.getItem("item");
    this.User_Code = JSON.parse(sessionStorage.getItem("UserInfo")).sUser_Code;
     this.user = userStore();
    this.GetZytzlist();
    this.Get_ZytzRecom_TzIds()
  },
  computed:{
       tztoo(){
       return(option)=>{
        console.log("ot",option)
                this.options.forEach((item1)=>{
                  if(option==item1.Tz_Id){
                    return true
                  }else{
                    return false
                  }
                })

       }
       }
  },
  methods: {
    GetZytzlist() {
       this.isButtonDisabled = true;
      axios
        .post(
          window.globalUrl.server + "Service.asmx/GetZytzlist",
          JSON.stringify({
            User_Code: this.User_Code,
            Interface_Code: this.Interface_Code,
          })
        )
        .then((res) => {
          if (res.data.RltCode == 1) {
             this.isButtonDisabled = false;
            console.log(res);
            this.sct = JSON.parse(res.data.RltData);
          }
        });
    },
    handleCheckboxChange(option) {
      console.log(option);
      this.RltTzID = option.Tz_Id;
      this.RltTzStr1=option.Tz_Name
    },
    Get_ZytzRecom_TzIds(){
     axios
        .post(
          window.globalUrl.server + "Service.asmx/Get_ZytzRecom_TzIds",
          JSON.stringify({
            User_Code: this.User_Code,
            Interface_Code: this.Interface_Code,
            Bmi_Val:this.user.Get_CheckSub_Data1.Sub_Bmi,
            YaoWei_Val:this.user.Get_CheckSub_Data1.Sub_Waistline
          })
        )
        .then((res) => {
          if (res.data.RltCode == 1) {
            this.options=JSON.parse(res.data.RltData)
            console.log("体质类型",this.options)
            console.log(res);
         
          }
        });
    },
     handleCheckboxChange1(option) {
      console.log(option);
      this.RltTzStr2=option.ppname
    },
    imaged() {
      this.$router.push("/souye");
    },
    onFinish({ selectedOptions }) {
      this.show = false;
      console.log(selectedOptions[0]);
      this.fieldValue = selectedOptions.map((option) => option.name).join("/");
      console.log(this.fieldValue);
    },
    submitForm(){
      const hasAtLeastOneMatch = this.options.some(element => element.Tz_Id==this.RltTzID)
      console.log("true",hasAtLeastOneMatch)
         axios
        .post(
          window.globalUrl.server + "Service.asmx/GetZytzQuestions",
          JSON.stringify({
            User_Code: this.User_Code,
            Interface_Code: this.Interface_Code,
            RltTzID:this.RltTzID,
            RltTzStr:this.RltTzStr1+this.RltTzStr2,
            BmiVal:hasAtLeastOneMatch==true?this.user.Get_CheckSub_Data1.Sub_Bmi:"",
            YaoVal:hasAtLeastOneMatch==true?this.user.Get_CheckSub_Data1.Sub_Waistline:""
          })
        )
        .then((res) => {
          if (res.data.RltCode == 1) {
            console.log("99999",JSON.parse(res.data.RltData));
            this.ZytzQuestions=JSON.parse(res.data.RltData)
            this.user.ZytzQuestions=this.ZytzQuestions
            sessionStorage.setItem("zs",JSON.stringify(this.ZytzQuestions))
             if(this.selectedValues1==""){
                showDialog({
               message: "偏颇程度未选择，请选择偏颇程度",
            })
           }else if(this.selectedValues==""){
               showDialog({
               message: "体质类型未选择，请选择体质类型",
            })
           } else if(this.selectedValues!=""&&this.selectedValues1!=""){
             this.$router.push({path:"/sys",query:{code:"1"}})
           }
           
          }
        });
    }
  },
};
</script>
<style scoped>
.tz{
  color:blue;
}
.contranier-content{
    display: flex;
}
.contranier {
  width: 100%;
  height: 100%;
  overflow: auto;
}
.contranier-title {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  padding-left: 20px;
  z-index: 1000;
  background-color: #d3c3a9;
}
.mmg {
  width: 40px;
  height: 40px;
}
.dialog-footer {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
}
.t1 {
  width: 100px;
  height: 40px;
}
.t2 {
  width: 100px;
  height: 40px;
}
::v-deep .van-radio__label {
  font-size: 20px;
}
::v-deep .van-radio {
  height: 40px;
}
::v-deep .van-radio-group {
  width: 30vw;
}
</style>
